package com.liy.supercloud.ssoserver.feign;

import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.webmsg.WebMessage;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class WebMessageClientFallbackFactory implements FallbackFactory<WebMessageClient> {

    private static final Logger log = LoggerFactory.getLogger(WebMessageClientFallbackFactory.class);


    public WebMessageClient create(final Throwable e) {
        log.info("webmessage feign fallback; reason was: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return new WebMessageClient() {
            public ResultVO sendClient(WebMessage message, String clientId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("Web消息服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO sendGroup(WebMessage message, String groupId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("Web消息服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO sendRole(WebMessage message, String roleId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("Web消息服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }
        };
    }
}
